import request from '@/utils/request'

/**
 * 角色管理
 * @param {*} params
 */
export function rolesQuery(params) {
  return request.get(`/platform/security/roles`, { params })
}

/**
 * 增加角色
 * @param {*} data
 */
export function roleAdd(data) {
  return request.post('/platform/security/roles', data)
}

/**
 * 角色信息
 * @param {*} data
 */
export function roleDetail(id) {
  return request.get(`/platform/security/roles/${id}`)
}

/**
 * 角色权限
 * @param {*} data
 */
export function roleJurisdiction(id) {
  return request.get(`/platform/security/roles/${id}/actions`);
}

/**
 * 编辑角色
 * @param {*} data
 */
export function roleEdit(data) {
  return request.patch(`/platform/security/roles/${data.id}`, data);
}

/**
 * 删除角色
 * @param {*} data
 */
export function roleDelete(id) {
  return request.delete(`/platform/security/roles/${id}`);
}

/**
 * 获取角色的所有权限
 *
 * @export
 * @param {*} roleId
 * @returns
 */
export function getActionsByRole(roleId) {
  return request.get(`/platform/security/roles/${roleId}/actions`)
}

/**
 * 保存角色权限
 *
 * @export
 * @param {*} roleId
 * @param {*} actions
 * @returns
 */
export function editRoleActions(roleId, actionIds) {
  return request.patch(`/platform/security/roles/${roleId}/actions`, { actionIds })
}

/**
 * 获取所有角色
 *
 * @export
 * @returns
 */
export function roleAll() {
  return request.get('/platform/security/roles/names')
}
